package leetcode.code2381;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public String shiftingLetters(String s, int[][] shifts) {
		int len = s.length();
		int[] hash = new int[len + 1];
		for (int i = 0; i < shifts.length; i++) {
			int[] shift = shifts[i];
			int start = shift[0], end = shift[1], d = shift[2];
			int add = d == 1 ? 1 : -1;
			hash[start] += add;
			hash[end + 1] -= add;
		}
		char[] ans = new char[len];
		for (int i = 0, sum = 0; i < len; i++) {
			sum += hash[i];
			ans[i] = (char) (((((s.charAt(i) - 'a' + sum) % 26) + 26) % 26) + 'a');
		}
		return new String(ans);
	}

	@Override
	public void debug4() {
		this.shiftingLetters("abc", H.str2array1("[[0,1,0],[1,2,1],[0,2,1]]"));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
